import { defineEventHandler, readBody } from 'h3';

export default defineEventHandler(async (event) => {
  const body = await readBody(event);

  // 模拟新增资源
  const newResource = {
    id: Date.now(), // 模拟生成ID
    ...body,
    create_time: new Date().toISOString(),
    update_time: new Date().toISOString(),
    creator: 'admin',
    updater: 'admin',
    deleted: 0,
    tenant_id: 1,
  };

  // 根据资源类型和子类型设置冗余字段
  const resourceTypeConfig = {
    PHYSICAL: '物理资源',
    HUMAN: '人力资源',
    DIGITAL: '数字资源',
    SERVICE: '服务资源',
    BUSINESS: '业务资源',
    TECHNICAL: '技术资源',
  };

  const resourceSubTypeConfig = {
    BUILDING: '建筑物',
    FLOOR: '楼层',
    ROOM: '房间',
    EQUIPMENT: '设备',
    VEHICLE: '车辆',
    FURNITURE: '家具',
    TEAM: '团队',
    INDIVIDUAL: '个人',
    DEPARTMENT: '部门',
    SOFTWARE: '软件',
    MODULE: '模块',
    API: '接口',
    DATABASE: '数据库',
    FILE: '文件',
    SERVICE: '服务',
    PROCESS: '流程',
    WORKFLOW: '工作流',
    PRODUCT: '产品',
    ORDER: '订单',
    CUSTOMER: '客户',
    COMPONENT: '组件',
    LIBRARY: '库',
    FRAMEWORK: '框架',
  };

  const businessTypeConfig = {
    HOTEL: '酒店业务',
    APARTMENT: '公寓业务',
    SPA: '温泉洗浴',
    SCENIC: '景区业务',
    RESTAURANT: '餐饮业务',
    MEDICAL_BEAUTY: '医美业务',
    BEAUTY_SALON: '美容美发',
    HUMAN: '人力资源',
  };

  // 设置冗余字段
  newResource.resource_type_name =
    resourceTypeConfig[newResource.resource_type] || newResource.resource_type;
  newResource.resource_sub_type_name =
    resourceSubTypeConfig[newResource.resource_sub_type] ||
    newResource.resource_sub_type;
  newResource.business_type_name =
    businessTypeConfig[newResource.business_type] || newResource.business_type;

  return {
    code: 200,
    message: '新增资源成功',
    data: newResource,
  };
});
